package com.yuyou.fn.timer.task;

import com.github.wens.mybatisplus.examples.Example;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.common.util.Utils;
import com.yuyou.fn.educational.entity.ClassTime;
import com.yuyou.fn.educational.entity.CourseClass;
import com.yuyou.fn.educational.entity.FinishLecture;
import com.yuyou.fn.educational.entity.StudentReg;
import com.yuyou.fn.educational.service.IClassTimeService;
import com.yuyou.fn.educational.service.ICourseClassService;
import com.yuyou.fn.educational.service.IFinishLectureService;
import com.yuyou.fn.educational.service.IStudentRegService;
import com.yuyou.fn.settlement.constant.Subjects;
import com.yuyou.fn.settlement.entity.ChangeRecord;
import com.yuyou.fn.settlement.service.ISettlementService;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * Created by wens on 2017/4/19.
 */
public class CalCourseTeacherCostTask implements Runnable {

    @Resource
    private IFinishLectureService finishLectureService ;

    @Resource
    private ISettlementService settlementService ;

    @Resource
    private ICourseClassService courseClassService ;

    @Resource
    private IClassTimeService classTimeService ;


    @Override
    public void run() {

        Example<FinishLecture> finishLectureExample = FinishLecture.createExample();
        finishLectureExample.createCriteria().andEqualTo("isCalTeacherCost" , "0");

        List<FinishLecture> finishLectureList = finishLectureService.findListByExample(finishLectureExample);

        for(FinishLecture finishLecture : finishLectureList ){
            CourseClass courseClass = courseClassService.findById(finishLecture.getClassId());
            ClassTime classTime = classTimeService.findByClassIdLectureNo(finishLecture.getClassId(), finishLecture.getLectureNo());

            //todo 计算老师薪酬

            BigDecimal amount = new BigDecimal("10");
            settlementService.bookTeacherCost(courseClass.getBusTeamId(),classTime.getTeacherId(),amount,courseClass.getClassName(),courseClass.getClassNo(),courseClass.getClassId(),finishLecture.getFinishLectureId()) ;

            FinishLecture update = new FinishLecture() ;
            update.setFinishLectureId(finishLecture.getFinishLectureId());
            update.setIsCalTeacherCost(1);
            update.setUpdateTime(TimeUtils.now());
            finishLectureService.updateSelectiveById(update);

        }

    }

}
